home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1998 August / PC Plus SuperCD 50b Issue 142 (CD142b) (August 1998).iso / essent / FIXES / CSeries.exe / issue99 / CPROG4.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-04  |  1.1 KB  |  31 lines

  1. #include <stdio.h>
  2.  
  3. #define VAT 0.175
  4.  
  5. main()
  6. {
  7. float cost;    // Create a floating-point variable called 'cost'
  8.  
  9.     printf("The VAT rate is %f percent\n", VAT*100);
  10.         /*----------------------------------------------------------+
  11.         | Note how we use %f to handle a floating point number. The |
  12.         | 'VAT' inside the string is not converted because the      |
  13.         | contents of strings are taken literally - unless there's  |
  14.         | a special modifier code like \ or %.                      |
  15.         |   The second, naked 'VAT', however, is expanded to 0.175. |
  16.         +----------------------------------------------------------*/
  17.     cost=1.50;  // Assign the value 1.5 to cost
  18.     printf("The cost is £%f\n", cost);  // Print it
  19.     cost=cost+(cost*VAT);        //Add VAT to it
  20.     printf("The cost, including VAT, is £%.2f\n", cost); //Print again
  21.         /*-------------------------------------------------------+
  22.         | See how .2 has been inserted between % and f. This     |
  23.         | truncates the number to two decimal places. Truncating |
  24.         | is not the same as rounding!                 |
  25.         +-------------------------------------------------------*/
  26.  
  27. }
  28.  
  29. // Press Alt+F5 to see the output screen
  30.  
  31.